<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>规格列表</title>
    <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css?v=2.8.12" />
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
    <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
</head>
<body>

<form class="layui-form" action="" lay-filter="create-table-form">

    <div class="mainBox">
        <div class="main-container">

            <div class="layui-tab layui-tab-brief" lay-filter="create-table-tab">
                <div class="layui-tab-content">

                    <div class="layui-tab-item layui-show">

                        <table id="column-table" lay-filter="column-table"></table>

                        <script type="text/html" id="col-type">
                            <select name="columns[{{ d.LAY_NUM-1 }}][type]" lay-verify="" disabled="">
                                {{# layui.each([{"id":"1","name":"成人"},{"id":"2","name":"儿童"}], function (index, item) { }}
                                <option value="{{ item.id }}" {{ d.type==item['id']?"selected":""}}>{{ item.name }}</option>
                                {{#  }); }}
                            </select>
                        </script>

                        <script type="text/html" id="col-comment">
                            <input type="text" name="columns[{{ d.LAY_NUM-1 }}][goods_original_price]" placeholder="商品原价" autocomplete="off" class="layui-input" value="{{ d.goods_original_price }}">
                        </script>

                        <script type="text/html" id="col-length">
                            <input type="text" name="columns[{{ d.LAY_NUM-1 }}][goods_sale_price]" placeholder="商品售价" autocomplete="off" class="layui-input" value="{{ d.goods_sale_price }}">
                        </script>

                        <script type="text/html" id="col-nullable">
                            <input type="checkbox" name="columns[{{ d.LAY_NUM-1 }}][status]" autocomplete="off" class="layui-input" value="{{ d.status }}" lay-skin="primary" {{ (d.status==1) ? 'checked' : '' }} >
                        </script>
                    </div>

                </div>
            </div>


        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                    lay-filter="save">
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-md">
                重置
            </button>
        </div>
    </div>
</form>

<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script src="/app/admin/admin/js/permission.js"></script>
<script>

    const CREATE_API = "/app/admin/rl-goods/updateSpecification";
    const specification_API = "/app/admin/rl-goods/specification";
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    // 字段设置
    layui.use(["table", "common", "popup","jquery"], function () {
        window._field_id = 0;
        var $ = layui.jquery;
        let table = layui.table;
        let cols = [
            {
                title: "人员类型",
                field: "type",
                templet: "#col-type",
                width: '30%',
            },
            {
                title: "商品原价",
                field: "goods_original_price",
                templet: "#col-comment",
                width: '25%'
            },
            {
                title: "销售价格",
                field: "goods_sale_price",
                templet: "#col-length",
                width: '25%'
            },
            {
                title: "是否启用",
                field: "status",
                templet: "#col-nullable",
                width: '20%',
                align: "center",
            }
        ];
        $(document).ready(function(){
            console.log('页面加载完成');
            layui.use(["jquery"], function() {
                layui.$.ajax({
                    url: specification_API,
                    dataType: "json",
                    type: "POST",
                    data: {'goods_id':getUrlParam('id')},
                    success: function (res) {
                        table.render({
                            elem: "#column-table",
                            cols: [cols],
                            data: res.data,
                            cellMinWidth: 40,
                            skin: "line",
                            size: "lg",
                            limit: 10000,
                            page: false,
                            toolbar: "#column-toolbar",
                            defaultToolbar: [],
                        });
                    }
                });
            });
        });

    });


    layui.use(["form", "popup"], function () {
        //提交事件
        layui.form.on("submit(save)", function () {
            let data = layui.form.val("create-table-form");
            data.goods_id=getUrlParam('id');
            layui.$.ajax({
                url: CREATE_API,
                type: "POST",
                dateType: "json",
                data: data,
                success: function (res) {
                    if (res.code) {
                        return layui.popup.failure(res.msg);
                    }
                    return layui.popup.success("操作成功", function () {
                        parent.refreshTable();
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    });
                }
            });
            return false;
        });
    });

</script>

</body>
</html>
